package org.zecontech.plantvszombie.mixin;


import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.zecontech.plantvszombie.api.event.PlantVsZombieEvents;

@Mixin(Mob.class)
public class MixinMob {

	@Shadow @Final protected GoalSelector goalSelector;

	@Shadow @Final protected GoalSelector targetSelector;

	@Inject(method = "<init>", at = @At("RETURN"))
	private void callMobInitEvent(EntityType<?> entityType, Level level, CallbackInfo ci) {
		if (level instanceof ServerLevel) {
			PlantVsZombieEvents.INIT_GOAL.invoker().initGoal(((Mob) (Object) this), this.goalSelector, this.targetSelector);
		}
	}
}